package com.cat.dataStructure;

import java.util.HashMap;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/count-the-number-of-beautiful-subarrays/
 * @create 2025/8/16 16:04
 * @since JDK17
 */

public class Solution28 {
    static HashMap<Integer, Integer> map = new HashMap<>();
    public long beautifulSubarrays(int[] nums) {
        map.clear();
        map.put(0, 1);
        long ans = 0;
        int n = nums.length, sum = 0;
        for (int i = 0, cnt; i < n; i++) {   //
            sum ^= nums[i];
            cnt = map.getOrDefault(sum, 0);
            ans += cnt;
            map.put(sum, cnt + 1);
        }

        return ans;
    }
}
